'''
Created on 2009-10-22

@author: summit
'''
import wx
import wx.aui

#from jolly.tvisual.PythonViewImage2D import *
from jolly.visual.vtkPythonViewImageCollection import *
from jolly.visual.vtkPythonViewImage2D import *
from jolly.visual.vtkPythonViewImage3D import *

from jolly.wxext.wxVTKPageView import *
from jolly.wxext.wxPythonViewImage2DPanel import *
from jolly.wxext.wxPythonViewImage3DPanel import *
from jolly.wxext.wxImportDirPanel import *
from jolly.wxext.wxMeasurePanel import *

from jolly.datamanagement.vtkPythonDataManager import *

#from jolly.tvisual.PythonViewImage3D import *

class Yuki(wx.Frame):
    '''
    classdocs
    '''
    __viewxy=None
    __viewyz=None
    __viewxz=None
    __view3D=None
    
    __configurexyPanel=None
    __configureyzPanel=None
    __configurexzPanel=None
    __configure3DPanel=None
    
    __viewtraitsxy=None
    __viewtraitsyz=None
    __viewtraitsxz=None
    __viewtraits3D=None
    
    __vtkpageview=None
    
    __viewcollection=None
    
    
    def __init__(self, parent, id=wx.ID_ANY, title="", pos= wx.DefaultPosition,
                 size=(1024, 768), style=wx.DEFAULT_FRAME_STYLE|wx.SUNKEN_BORDER|wx.MAXIMIZE):
        '''
        Constructor
        '''
        wx.Frame.__init__(self, parent, id, title, pos, size, style)
        
        self.__vtkpageview=wxVTKPageView(self, wx.ID_ANY)
        self.__viewcollection = vtkPythonViewImageCollection()
        self.__view3D = vtkPythonViewImage3D()
        self.__viewcollection.AddItem(self.__view3D)
        self.__datamanager = vtkPythonDataManager()
        
        self.__viewxy = vtkPythonViewImage2D()
        self.__viewxy.SetInput(None)
        self.__viewxy.GlobalWarningDisplayOff()
        self.__viewxy.SetupInteractor(self.__vtkpageview.viewInteractor1)
        self.__viewxy.SetRenderWindow(self.__vtkpageview.viewInteractor1.GetRenderWindow())
        self.__viewxy.SetInteractorStyleTypeToNavigation()
        self.__viewxy.SetSliceOrientationToXY()
        self.__view3D.Add2DPhantom(self.__viewxy.GetImageActor())
        self.__viewcollection.AddItem(self.__viewxy)
#        self.__viewtraitsxy = PythonViewImage2D(self.__viewxy)
#        self.__viewtraitsxy.set_observer(self.__viewcollection)
#        self.__configurexyPanel = pythonviewimage2d_view
        
        self.__viewyz = vtkPythonViewImage2D()
        self.__viewyz.SetInput(None)
        self.__viewyz.GlobalWarningDisplayOff()
        self.__viewyz.SetupInteractor(self.__vtkpageview.viewInteractor2)
        self.__viewyz.SetRenderWindow(self.__vtkpageview.viewInteractor2.GetRenderWindow())
        self.__viewyz.SetInteractorStyleTypeToNavigation()
        self.__viewyz.SetSliceOrientationToYZ()
        self.__viewcollection.AddItem(self.__viewyz)
        self.__view3D.Add2DPhantom(self.__viewyz.GetImageActor())
#        self.__viewtraitsyz = PythonViewImage2D(self.__viewyz)
#        self.__viewtraitsyz.set_observer(self.__viewcollection)
#        self.__configureyzPanel = pythonviewimage2d_view
       
        self.__viewxz = vtkPythonViewImage2D()
        self.__viewxz.SetInput(None)
        self.__viewxz.GlobalWarningDisplayOff()
        self.__viewxz.SetupInteractor(self.__vtkpageview.viewInteractor3)
        self.__viewxz.SetRenderWindow(self.__vtkpageview.viewInteractor3.GetRenderWindow())
        self.__viewxz.SetInteractorStyleTypeToNavigation()
        self.__viewxz.SetSliceOrientationToXZ()
        self.__viewcollection.AddItem(self.__viewxz)
        self.__view3D.Add2DPhantom(self.__viewxz.GetImageActor())
#        self.__viewtraitsxz = PythonViewImage2D(self.__viewxz)
#        self.__viewtraitsxz.set_observer(self.__viewcollection)
#        self.__configurexzPanel = pythonviewimage2d_view
        
        
        self.__view3D.SetInput(None)
        self.__view3D.GlobalWarningDisplayOff()
        self.__view3D.SetupInteractor(self.__vtkpageview.viewInteractor4)
        self.__view3D.SetRenderWindow(self.__vtkpageview.viewInteractor4.GetRenderWindow())
#        self.__view3D.SetRenderingModeToVR()
        self.__view3D.SetRenderingModeToPlanar()
        self.__view3D.InstallPipeline()
#        self.__viewtraits3D = PythonViewImage3D(self.__view3D)
#        self.__viewtraits3D.set_observer(self.__viewcollection)
#        self.__configure3DPanel = pythonviewimage3d_view
        
        self.__mgr = wx.aui.AuiManager()
        self.__mgr.SetFlags(wx.aui.AUI_MGR_RECTANGLE_HINT or wx.aui.AUI_MGR_ALLOW_ACTIVE_PANE )
        self.__mgr.SetManagedWindow(self)
        self.DoLayout()
    
    def DoLayout(self):
        self.__mgr.AddPane(self.__vtkpageview, wx.aui.AuiPaneInfo().Name("PageView").Caption("PageView").CenterPane().PaneBorder(False))
        self.__mgr.AddPane(self.CreatePanel(), wx.aui.AuiPaneInfo().Name("configure_panel").Caption("configure").
                          Left().Layer(1).Position(1).CloseButton(True).MaximizeButton(True).
                          MinimizeButton(True).MinimizeButton(True))
        
        self.__mgr.Update()
        
#    def CreateConfigureNoteBook(self):
#        client_size = self.GetClientSize()
#        ctrl = wx.aui.AuiNotebook(self, -1, wx.Point(0, 0), wx.Size(160, 250), 
#                              wx.aui.AUI_NB_DEFAULT_STYLE | wx.aui.AUI_NB_TAB_EXTERNAL_MOVE | wx.NO_BORDER)
#
#        ctrl.AddPage(self.__configurexyPanel.ui(parent=ctrl, context=self.__viewtraitsxy).control, "xy configure")
#        ctrl.AddPage(self.__configureyzPanel.ui(parent=ctrl, context=self.__viewtraitsyz).control, "yz configure")
#        ctrl.AddPage(self.__configurexzPanel.ui(parent=ctrl, context=self.__viewtraitsxz).control, "xz configure")
#        ctrl.AddPage(self.__configure3DPanel.ui(parent=ctrl, context=self.__viewtraits3D).control, "3D configure")
#        return ctrl
    
    def CreatePanel(self, vertical=True):
     
        newstyle = (vertical and [fpb.FPB_VERTICAL] or [fpb.FPB_HORIZONTAL])[0]
        bar = fpb.FoldPanelBar(self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize,
                       fpb.FPB_DEFAULT_STYLE | newstyle, fpb.FPB_COLLAPSE_TO_BOTTOM)
        
        item = bar.AddFoldPanel("Import Panel", collapsed=False)
        importmodel = ImportModel(self.__viewcollection, self.__datamanager)
       
        importpanel = ImportDirPanel(item, wx.ID_ANY, importmodel)
        bar.AddFoldPanelWindow(item, importpanel, fpb.FPB_ALIGN_WIDTH, 0, 20)
        
        item = bar.AddFoldPanel("MeasurePanel Panel",collapsed=False)
        measurepanel = MeasurePanel(item, wx.ID_ANY, MeasureModel(self.__datamanager))
        bar.AddFoldPanelWindow(item, measurepanel, fpb.FPB_ALIGN_WIDTH, 0, 20)
        
        importmodel.addListener(measurepanel.UpdateControl)
        
        item = bar.AddFoldPanel("Edit xy-View2D properties", collapsed=True)
        xypanel = PythonViewImage2DPanel(item, wx.ID_ANY, PythonViewImage2DModel(self.__viewxy, self.__viewcollection, self))
        bar.AddFoldPanelWindow(item, xypanel, fpb.FPB_ALIGN_WIDTH, 0, 20)
        
        item = bar.AddFoldPanel("Edit yz-View2D properties", collapsed=True)
        yzpanel = PythonViewImage2DPanel(item, wx.ID_ANY, PythonViewImage2DModel(self.__viewyz, self.__viewcollection, self))
        bar.AddFoldPanelWindow(item, yzpanel, fpb.FPB_ALIGN_WIDTH, 0, 20)
        
        
        item = bar.AddFoldPanel("Edit xz-View2D properties", collapsed=True)
        xzpanel = PythonViewImage2DPanel(item, wx.ID_ANY, PythonViewImage2DModel(self.__viewxz, self.__viewcollection, self))
        bar.AddFoldPanelWindow(item, xzpanel, fpb.FPB_ALIGN_WIDTH, 0, 20)
        
        item = bar.AddFoldPanel("Edit View3D properties", collapsed=True)
        threedpanel = PythonViewImage3DPanel(item, wx.ID_ANY, PythonViewImage3DModel(self.__view3D, self.__viewcollection, self))
        bar.AddFoldPanelWindow(item, threedpanel, fpb.FPB_ALIGN_WIDTH, 0, 20)
        
        
        if hasattr(self, "pnl"):
            self.pnl.Destroy()

        self.pnl = bar

        size = self.GetClientSize()
        self.pnl.SetDimensions(0, 0, size.GetWidth(), size.GetHeight())
        return self.pnl
    
    def getViewxy(self):
        return self.__viewxy


    def getViewyz(self):
        return self.__viewyz


    def getViewxz(self):
        return self.__viewxz


    def getView3D(self):
        return self.__view3D


    def setViewxy(self, value):
        self.__viewxy = value


    def setViewyz(self, value):
        self.__viewyz = value


    def setViewxz(self, value):
        self.__viewxz = value


    def setView3D(self, value):
        self.__view3D = value


    def delViewxy(self):
        del self.__viewxy


    def delViewyz(self):
        del self.__viewyz


    def delViewxz(self):
        del self.__viewxz


    def delView3D(self):
        del self.__view3D

    viewxy = property(getViewxy, setViewxy, delViewxy, "Viewxy's Docstring")

    viewyz = property(getViewyz, setViewyz, delViewyz, "Viewyz's Docstring")

    viewxz = property(getViewxz, setViewxz, delViewxz, "Viewxz's Docstring")

    view3D = property(getView3D, setView3D, delView3D, "View3D's Docstring")


if __name__ == '__main__':
    app = wx.PySimpleApp()
    frame = Yuki(None)
    frame.Show(True)
    app.MainLoop()